/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 解析.node.node;

import 解析.node.others.TreeInfo;
import 解析.Matcher;

/**
 *
 * @author yanxi
 */
public class LineEnding extends Node {

    @Override
    public boolean match(Matcher matcher, int i, CharSequence seq) {
        // (u+000Du+000A|[u+000Au+000Bu+000Cu+000Du+0085u+2028u+2029])
        if (i < matcher.to) {
            int ch = seq.charAt(i);
            if (ch == 0x0A || ch == 0x0B || ch == 0x0C
                    || ch == 0x85 || ch == 0x2028 || ch == 0x2029) {
                return next.match(matcher, i + 1, seq);
            }
            if (ch == 0x0D) {
                i++;
                if (i < matcher.to && seq.charAt(i) == 0x0A) {
                    i++;
                }
                return next.match(matcher, i, seq);
            }
        } else {
            matcher.hitEnd = true;
        }
        return false;
    }

    @Override
    public boolean study(TreeInfo info) {
        info.minLength++;
        info.maxLength += 2;
        return next.study(info);
    }
}
